﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SharpDiary.Core.Common;
using SharpDiary.Core.Attributes;

namespace SharpDiary.Note
{
    [ModuleAttribute("65b706fa-0052-40ae-bb19-38cbb4d93d87", "NoteManager", "Ray Shaw(demogodyou@gmail.com)(demogodyou@gmail.com)")]
    public partial class frmNoteManager : GuiModuleUIBase
    {
        public frmNoteManager()
        {
            InitializeComponent();
        }

        public override string GetSettingsKeyName()
        {
            return this.Name;
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            Close();
        }

        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);

            noteInfoListControl.ShowItems();
        }

        private void RefreshData()
        {
            noteInfoListControl.ShowItems();
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            noteInfoListControl.ShowItems();
        }

        private void btnNew_Click(object sender, EventArgs e)
        {
            OwnerShell.ExecuteAction("SharpDiary.Note", "c1498ab4-7301-4c30-8de1-e9516d6e9724", null, this);
        }

        public override void OnMessageReceived(object sender, MessageReceivedEventArgs e)
        {
            base.OnMessageReceived(sender, e);

            if (e.TargetModuleId.Equals("65b706fa-0052-40ae-bb19-38cbb4d93d87", StringComparison.CurrentCultureIgnoreCase))
            {
                switch (e.MessageInfo)
                {
                    case MessageDefinition.Refresh:
                        {
                            RefreshData();
                            break;
                        }
                }
            }
        }
    }
}
